
#ifndef __OBJECT_HPP__
#define __OBJECT_HPP__

#include <string>
#include <map>

#include "GameComponent.h"

typedef std::string obj_id_type;

class GameObject {
public:
	GameObject( const obj_id_type& id) {
		setID(id);
	}

	const obj_id_type& getID() const { return mOID; }
	void setID( const obj_id_type& id ) { mOID = id; }

	GameComponent* getComponent(const comp_id_type& familyID ) {
		std::map<const comp_id_type, GameComponent*>::iterator iter = mComponents.begin();
		iter = mComponents.find(familyID);
		
		if(iter != mComponents.end()) 
			return iter->second;
		
		return NULL;
	}

	GameComponent* setComponent(GameComponent *newComp) {
		comp_id_type family = newComp->familyID();
		GameComponent *oldComp = mComponents[family];
		newComp->setOwnerObject(this);
		mComponents[family] = newComp;
		return oldComp;
	}

	void clearComponents() {
		std::map<const comp_id_type, GameComponent*>::iterator iter;
		for(iter = mComponents.begin(); iter != mComponents.end(); iter++) {
			delete iter->second;
			
		}
		mComponents.clear();
	}

	void update() {
		std::map<const comp_id_type, GameComponent*>::iterator iter;
		for(iter = mComponents.begin(); iter != mComponents.end(); iter++) {
			iter->second->update();
		//	dynamic_cast<GameComponent*>(*iter)->update();
		}
	}
	void setup() {
		std::map<const comp_id_type, GameComponent*>::iterator iter;
		for(iter = mComponents.begin(); iter != mComponents.end(); iter++) {
			iter->second->setup();
		}
	}

private:
	obj_id_type mOID;			//unique identifier for this object

	std::map<const comp_id_type, GameComponent*> mComponents; 
	
	//typedef 
	//component_table_type;
	//component_table_type mComponents;		//map of all components;
};

#endif
